Welcome Guest | Sign in | Register

Home > Java Programming > Language Fundamentals > Questions and Answers

01. What will happen if you try to compile and run this ?
public class Test{
static{
print(10);
}
static void print(int x){
System.out.println(x);
System.exit(0);
}
}
A. Compiler error. B. Will throw a NoSuchMethod error at runtime.
C. It will compile and run printing out "10" D.  It will run with no output.
E. It will run and print "10" and then crash with an error.      

Answer and Explanation

Answer: It will compile and run printing out "10"

Explanation:
This will run, print a message and terminate gracefully.
The runtime system needs to load the class before it can look
for the main method. So the static initializer will run first
and print "10". Immediately after that System.exit(0) will be called
terminating the program before an error can be thrown. 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Is this legal?
long longArr[];
int intArr[] = { 7 ,8 , 9};
longArr = intArr;
A. yes B. no
C. cannot be determined D. not applicable

Answer and Explanation

Answer: no

Explanation:
You cannot assign a reference to an array of primitives
to another unless they contain the same primitive types. 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. True or False.
The range of a byte is from -127 to 128
A. True B. False
C. Cannot be determined D. Error

Answer and Explanation

Answer: False

Explanation:
The statement is false. The range of an array
is from - 128 to 127 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Identify the valid assignments.

1. float f = \u0038;
2. long L2 = 2L;
3. float f = 1.2;
4. char c = '/u004E';
5. byte b = 100;
A. 2,3,4 B. 1,2,3,4
C. 4,5 D. 1,2,5

Answer and Explanation

Answer: 1,2,5

Explanation:
1 is correct because \u0038 is unicode for nbr 8.
3 is wrong because 1.2 is a double literal.
4. is a little sneaky perhaps. The
unicode escape character is incorrect

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What is the result of trying to compile and run the following code.
public static void main(String[] args){
double d = 10 / 0;
if(d == Double.POSITIVE_INFINITY)
System.out.println("Positive infinity");
else
System.out.println("Negative infinity");
}
A. output Positive infinity B. output Negative infinity
C. Will fail to compile D. Runtime exception

Answer and Explanation

Answer: Runtime exception

Explanation:
  Division by zero on integer literals will throw
a runtime error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What is the correct ordering for the import, class and package declarations when found in a single file?
A. package, import, class  B. class, import, package 
C. import, package, class  D. package, class, import

Answer and Explanation

Answer: package, import, class 

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.